/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */

#include "bits/stdc++.h"

using namespace std;

struct ListNode {
    int val;
    ListNode *next;

    ListNode(int x) : val(x), next(nullptr) {}
};

class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        unordered_map<long long, bool> hash;
        int index = 0;
        while (headA) {
            hash[(long long) headA] = true;
            headA = headA->next;
        }
        while (headB) {
            if (hash[(long long) headB])
                return headB;
        }
        return nullptr;
    }
};

int main() {

}